package route

import (
    "github.com/gin-gonic/gin"
    
    "collecter/app/controller/api"
    "collecter/app/middleware"
)

/*
 *  registerApiRouter
 * @Description: api 路由组
 * @param router
 * @return *gin.Engine
 */
func registerApiRouter(router *gin.Engine) *gin.Engine {
    router.GET("/", (&api.IndexController{}).Index)
    router.GET("/index", (&api.IndexController{}).Index)
    router.GET("/api/", (&api.IndexController{}).Index)
    router.GET("/api/index", (&api.IndexController{}).Index)
    
    router.GET("/api/authorize/activate", (&api.AuthorizeController{}).Activate)    // 账号激活
    router.POST("/api/authorize/send-code", (&api.AuthorizeController{}).SendVcode) // 发送验证码
    router.POST("/api/authorize/register", (&api.AuthorizeController{}).Register)   // 账号注册
    router.POST("/api/authorize/sign-in", (&api.AuthorizeController{}).Login)       // 登录
    router.POST("/api/authorize/bind", (&api.AuthorizeController{}).Bind)           // 绑定手机号或者邮箱账号
    router.POST("/api/authorize/refresh-token", (&api.AuthorizeController{}).RefersToken) // 刷新 access_token
    router.POST("/api/authorize/reset-password", (&api.AuthorizeController{}).ResetPassword) // 刷新 access_token
    
    apiRouter := router.Group("/api")
    apiRouter.Use(middleware.CheckAccessToken())
    {
        apiRouter.POST("/authorize/sign-out", (&api.AuthorizeController{}).Logout)           // 退出登录
        
        apiRouter.GET("/user/profile", (&api.UserController{}).Profile)
        apiRouter.POST("/user/modify", (&api.UserController{}).Modify)
        
        apiRouter.GET("/category/list", (&api.CategoryController{}).List)
        apiRouter.POST("/category/create", (&api.CategoryController{}).Create)
        apiRouter.POST("/category/delete", (&api.CategoryController{}).Delete)
        
        apiRouter.GET("/collect/list", (&api.CollectController{}).List)
        apiRouter.POST("/collect/create", (&api.CollectController{}).Create)
        apiRouter.POST("/collect/update", (&api.CollectController{}).Update)
        apiRouter.POST("/collect/delete", (&api.CollectController{}).Delete)
        
    }
    return router
}
